# -*- coding:utf-8 -*-
import xlrd
from scripts.TestRequest import TestGetRequest,TestPostRequest
from api.getpath import GetTestDataPath

testdata = xlrd.open_workbook(GetTestDataPath())
# table = testdata.sheets()[0]  # testdata.sheet_by_name(sheetname) 通过sheet名称来获取sheet对象
testurl = "http://127.0.0.1:8000"  # table.cell(0, 1).value


def post_vote():
    try:
        table = testdata.sheets()[1]
        for i in range(3, 5):
            choice = table.cell(i, 0).value
            status = table.cell(i, 1).value
            qiwang = table.cell(i, 2).value
            hdata = {
                'choice': int(choice)
            }
            header = {
                'content-type': "application/x-www-form-urlencoded"
            }
            testcaseid = "1-1"
            testname = "testvote" + testcaseid
            testhope = str(int(status))
            fanhuitesthpe = qiwang
            r = TestPostRequest(testurl + '/lagoutoupiao/1/vote/', hdata, header, testcaseid, testname, testhope,
                                fanhuitesthpe)
    except Exception as e:
        print(e)
    print("测试post_vote")


# post_vote()


def get_polls():
    try:
        table = testdata.sheets()[1]
        for i in range(13, 14):
            status = table.cell(i, 0).value
            qiwang = table.cell(i, 1).value
            hdata = ""
            header = {
                'content-type': "application/x-www-form-urlencoded"
            }
            testcaseid = "1-2"
            testname = "testpolls" + testcaseid
            testhope = str(int(status))
            fanhuitesthpe = qiwang
            r = TestGetRequest(testurl + '/lagoutoupiao/', hdata, header, testcaseid, testname, testhope, fanhuitesthpe,
                               "status")
    except Exception as e:
        print(e)
    print("测试get_polls")

# get_polls()
